//食谱相关接口
import request from "../../utils/request";

//统一接口
const API = {
  GET_MEALS: "/getMeals",
  GET_THREE_TYPE: "/getThreeMeal",
  GET_NEW_MEALS: "/newMeals",
  GET_FAV_TOP: "/topFavorite",
  SEARCH_MEALS: "/searchMeals",
  GET_HOT_LIST: "/hot_search",
  GET_DETAIL: "/getMeal",
  GET_SIMILAR: "/recommendSimilar",
  ADD_VIEW: "/addView",
  GET_ALL_MEALS: "/meals",
  GET_VIEW_TOP: "/top_ten_recipes",
  GET_TYPE_PERCENTAGE: "/meal_type",
  GET_FAV_TEN_TOP: "/top_fav_num",
  DELETE_MEAL: "/deleteMeal",
  DELETE_MEALS: "/deleteMeals",
  CREATE_MEAL: "/addMeal",
  ADD_MEAL: "/addMeal",
  HOST_MEALS: "/hotMeals",
  RECOMMEND_MEALS: "/recommendMeals",
};

//暴露请求函数
export const reqGetMeal = (num) => request.get(`${API.GET_MEALS}/${num}`);

export const reqGetThree = () => request.get(API.GET_THREE_TYPE);

export const reqNewMeals = () => request.get(API.GET_NEW_MEALS);

export const reqTopFav = () => request.get(API.GET_FAV_TOP);

export const reqSearch = (data) =>
  request.get(
    `${API.SEARCH_MEALS}?name=${data.name}&current_page=${data.page}&page_size=${data.limit}&sort_field=${data.sort_field}&sort_direction=${data.sort_direction}&type=${data.type}`
  );

export const reqHotList = () => request.get(API.GET_HOT_LIST);

export const reqDetail = (id) => request.get(`${API.GET_DETAIL}/${id}`);

export const reqSimilar = (data) =>
  request.get(
    `${API.GET_SIMILAR}?dish_name=${data.dish_name}&taste=${data.taste}&method=${data.method}&id=${data.id}`
  );

export const reqAddView = (id) => request.post(`${API.ADD_VIEW}?meal_id=${id}`);

export const reqAllMeals = (data) =>
  request.get(
    `${API.GET_ALL_MEALS}?page=${data.page}&per_page=${data.limit}&sort_field=${data.sort_field}&sort_direction=${data.sort_direction}&type=${data.type}&name=${data.name}`
  );
export const reqViewTop = () => request.get(API.GET_VIEW_TOP);

export const reqTypePercentage = () => request.get(API.GET_TYPE_PERCENTAGE);

export const reqFavTenTop = () => request.get(API.GET_FAV_TEN_TOP);

export const reqDeleteMeal = (id) => request.delete(`${API.DELETE_MEAL}/${id}`);

export const reqCreateMeal = (data) => request.post(API.CREATE_MEAL, data);

export const reqDeleteMeals = (idList) =>
  request.delete(API.DELETE_MEALS, { data: idList });

export const reqAddMeal = (data) => request.post(API.ADD_MEAL, data);

export const reqHostMeals = () => request.get(API.HOST_MEALS);

export const reqRecommendMeals = (id) =>
  request.post(`${API.RECOMMEND_MEALS}/${id}`);
